package com.xgf.common.xgfcommon.result;

import java.util.HashMap;
import java.util.Map;

import com.xgf.common.xgfcommon.result.code.ResultEnum;

public class ResponseBo<T> extends HashMap<String, Object>{
	private static final long serialVersionUID = 1L;
	
	public  static String CODE = "code";
	public static String MSG = "msg";
	public static String TOKEN = "token";
	

	public ResponseBo() {
		put(CODE, 0);
		put(MSG, "操作成功");
	}
	
	public static <T> ResponseBo<T> build(ResultEnum resultEnum) {
		ResponseBo<T> responseBo = new ResponseBo<T>();
		responseBo.put(CODE, resultEnum.getReasonCode());
		responseBo.put(MSG, resultEnum.getReasonName());
		
		
		return responseBo;
	}
	

	public static <T> ResponseBo<T> error() {
		return error(1, "操作失败");
	}

	public static <T> ResponseBo<T> error(String msg) {
		return error(500, msg);
	}

	public static <T> ResponseBo<T> error(int code, String msg) {
		ResponseBo<T> responseBo = new ResponseBo<T>();
			responseBo.put(CODE, code);
			responseBo.put(MSG, msg);
		return responseBo;
	}

	public static <T> ResponseBo<T> ok(String msg) {
		ResponseBo<T> responseBo = new ResponseBo<T>();
			responseBo.put("msg", msg);
		return responseBo;
	}

	public static <T> ResponseBo<T> ok(Map<String, T> map) {
		ResponseBo<T> responseBo = new ResponseBo<T>();
			responseBo.putAll(map);
		return responseBo;
	}

	public static <T> ResponseBo<T> ok() {
		return new ResponseBo<T>();
	}

	public static <T> ResponseBo<T> setData(T value) {
		ResponseBo<T> responseBo = new ResponseBo<T>();
			responseBo.put("data", value);
		return responseBo;
	}
	
	@Override
	public ResponseBo<T> put(String key, Object value) {
		super.put(key, value);
		return this;
	}
	
	public static <T> ResponseBo<T> setData(ResultEnum resultEnum) {
		ResponseBo<T> responseBo = new ResponseBo<T>();
			responseBo.put(MSG, resultEnum.getReasonName());
		return responseBo;
	}
}
